package com.tanhua.app.controller;

import com.itheima.model.dto.OptionsDto;
import com.itheima.model.vo.CharacterVo;
import com.itheima.model.vo.QuestionnaireVo;
import com.tanhua.app.service.TestSoulService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/testSoul")
public class TestSoulController {

    @Autowired
    private TestSoulService testSoulService;

    //测灵魂-问卷列表
    @GetMapping
    public ResponseEntity<List<QuestionnaireVo>> testSoul() {
        List<QuestionnaireVo> vos = testSoulService.testSoul();

        return ResponseEntity.ok(vos);
    }


    // 测灵魂-提交问卷
    @PostMapping
    public ResponseEntity<String> save(@RequestBody Map<String, List<OptionsDto>> params) {

        // 解析参数
        List<OptionsDto> answers = params.get("answers");
        String reportId = testSoulService.save(answers);

        return ResponseEntity.ok(reportId);
    }

    // 测灵魂-查看结果
    @GetMapping("/report/{id}")
    public ResponseEntity<CharacterVo> findCharacter(@PathVariable Long id) {

        CharacterVo vo = testSoulService.findCharacter(id);

        return ResponseEntity.ok(vo);

    }
}
